<extend name="Base/base" />
<block name='head'>
    <style>
    </style>
</block>
<block name="content"> 
    <section class="larry-wrapper pege-storage page-purchase" id="page-purchase">
        <form>
            <div class="row" >
                <div class="col-lg-12 col-sm-12">	
                    <div class="layui-tab layui-tab-brief " lay-filter="tabInfo">
                        <ul class="layui-tab-title">
                            <li class="layui-this first1 checkType" data-type="1">信息化产品出库</li>
                            <li class="second checkType" data-type="2">低值易耗品出库</li>
                            <input type="hidden" class="typeUrl" value="{:U('getGoodsData')}">
                            <input type="hidden" class="goodsUrl" value="{:U('getGoodsInfo')}">
                            <input type="hidden" name="type" value="1" />
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <table class="layui-table setTabBg inforTable" id="purchase" lay-skin="line">
                                    <colgroup>
                                        <col width="18%" />
                                        <col width="17%" />
                                        <col width="8%" />
                                        <col width="10%" />
                                        <col width="8%" />
                                        <col width="10%" />
                                        <col width="20%" />
                                        <col width="10%" />
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>物品名称</th>
                                            <th>规格型号</th>
                                            <th>单位</th>
                                            <th>库存数量</th>
                                            <th>出库数量</th>
                                            <th>总金额</th>
                                            <th>备注</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>
                                                <select class="layui-input search_input outGoods" name="goods_id[]">
                                                    <foreach name="goods" item="good">
                                                        <if condition="$good[type] eq 1">
                                                            <option value="{$good.id}">{$good.name}</option>
                                                        </if>
                                                    </foreach>
                                                </select>
                                            </td>
                                            <td class="model"></td>
                                            <td class="unit"></td>
                                            <td class="total"></td>
                                            <td><input type="text" name="count[]" class="layui-input count"></td>
                                            <td class="price"></td>
                                            <td><input type="text" name="remark[]" class="layui-input"></td>
                                            <td>
                                                <img src="/Public/Admin/images/add.png" class="pointer addBtn"/>
                                                <img src="/Public/Admin/images/del.png" class="pointer delBtn"/>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                                <a class="layui-btn submitBtn btn-submit ajax-post" data-url="{:U('outGoods')}">提交</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </section>
</block>
<block name="script">
    <script type="text/javascript" src="/Public/Admin/js/goods.js"></script>
    <script type="text/javascript">
        $(initGoods());
        layui.use(['jquery', 'layer', 'element'], function () {
            window.jQuery = window.$ = layui.jquery;
            window.layer = layui.layer;
            window.element = layui.element();
        });

        //判断库存
        var flag = true;
        $('body').on('blur', '.count', function () {
            var count = parseInt($(this).parent().prev().text());
            if (parseInt($(this).val()) > count) {
                layer.msg('出库数量不能大于库存');
                flag = false;
            }else{
                flag = true;
            }
        })

        //检查表单
        $('.ajax-post').on('click', function () {
            $('body').find('.count').each(function () {
                if ($(this).val() == '') {
                    layer.msg('物品数量不能为空');
                    flag = false;
                }
            })

            if (flag == false) {
                $(this).removeClass('btn-submit');
            } else {
                $(this).addClass('btn-submit');
            }
        })


    </script>    
    <script type="text/javascript" src="/Public/Admin/js/common.js" ></script>
</block>

